package unsafe;

import java.util.Map;
import java.util.UUID;
import java.util.concurrent.ConcurrentHashMap;


/**
 * @projectName: JUC
 * @package: unsafe
 * @className: mapTest
 * @author: 冷环渊 doomwatcher
 * @description: TODO
 * @date: 2022/3/2 11:08
 * @version: 1.0
 */
public class mapTest {
    //java.util.ConcurrentModificationException
    public static void main(String[] args) {
        //    map是这样用的吗 不是 工作中很少使用 Hashmap
        //    默认等价于什么 new HashMap<>(16,0.75);
        /*解决方案
         * juc包下的 new ConcurrentHashMap<>();
         * */
        Map<String, String> map = new ConcurrentHashMap<>();
        for (int i = 1; i <= 500; i++) {
            new Thread(() -> {
                map.put(Thread.currentThread().getName(), UUID.randomUUID().toString().substring(0, 5));
                System.out.println(map);
            }, String.valueOf(i)).start();
        }

    }
}
